#!/usr/bin/make -f

export DH_VERBOSE = 1

.ONESHELL:
include /etc/os-release

STATIC := 0 # can't use golang tracee-rules if enabled
BTFHUB := 1 # will include tailored BTF files from btfhub

TRACEE_MAKE = BTFHUB=$(BTFHUB) STATIC=$(STATIC) make

GO_PATH :=

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/pkg-info.mk

%:
	dh $@ --parallel

# do not call "clean" directly not to lose ./dist directory
override_dh_auto_clean:
	$(TRACEE_MAKE) clean

override_dh_auto_configure:

override_dh_auto_build:
	$(TRACEE_MAKE) clean
	$(TRACEE_MAKE) all

override_dh_auto_install:
	# tracee-ebpf
	mkdir -m 0755 -p ./debian/tracee-ebpf/usr/bin/
	install -m 0755 ./dist/tracee-ebpf ./debian/tracee-ebpf/usr/bin/
	# tracee-rules
	mkdir -m 0755 -p ./debian/tracee-rules/usr/bin/
	mkdir -m 0755 -p ./debian/tracee-rules/usr/lib/tracee/
	install -m 0755 ./dist/tracee-rules ./debian/tracee-rules/usr/lib/tracee/
	ln -s /usr/lib/tracee/tracee-rules ./debian/tracee-rules/usr/bin/tracee-rules
	# rules
	mkdir -m 0755 -p ./debian/tracee-rules/usr/lib/tracee/rules/
	install -m 0644 ./dist/rules/* ./debian/tracee-rules/usr/lib/tracee/rules/
ifeq ($(STATIC),1)
	rm ./debian/tracee-rules/usr/lib/tracee/rules/*.so
endif
